package com.vooda.business_admin.controller.homePage;

import com.vooda.business_admin.common.BaseController;
import com.vooda.business_admin.common.ReqDataTableDto;
import com.vooda.business_admin.common.RspDataTableDto;
import com.vooda.business_admin.entity.Market;
import com.vooda.business_admin.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 超市
 */
@RestController
@RequestMapping("/market")
public class MarketController extends BaseController{

    @Autowired
    private MarketService marketService;

    /**
     * 获取所有超市列表
     * @param dataTableDTO
     * @return
     */
    @GetMapping("/getAllList")
    public RspDataTableDto<Market> getAllList(ReqDataTableDto dataTableDTO,
                                              @RequestParam(value = "market",required = false) String market){

       return marketService.findAllMarketList(dataTableDTO,market);

    }

    /**
     *查单个超市
     * @return
     */
    @GetMapping("/editMarket/{id}")
    public Market editRole(HttpServletRequest request, @PathVariable("id") Long id){
       return marketService.selectByPrimaryKey(id);

    }

    /**
     *保存超市
     * @return
     */
    @PostMapping("/saveMarket")
    public String saveRole(Market market){

        return marketService.saveMarket(market);


    }

    /**
     * 删除超市
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/removeMarket/{id}")
    public String removeArticle(HttpServletRequest request, @PathVariable("id") Long id){
       return marketService.deleteByPrimaryKey(id);

    }

    /**
     * 获取所有超市
     * @return
     */
    @GetMapping("/getList")
    public List<Market> getList(){

        return marketService.getMarketList();

    }
}
